package org.witsoft.demo.graphql.extend.scalar;

import graphql.schema.Coercing;
import graphql.schema.CoercingParseLiteralException;
import graphql.schema.CoercingParseValueException;
import graphql.schema.CoercingSerializeException;

import java.util.Date;

public class DateCoercing implements Coercing<Date, Long> {


    @Override
    public Long serialize(Object obj) throws CoercingSerializeException {
        return ((Date)obj).getTime();
    }

    @Override
    public Date parseValue(Object input) throws CoercingParseValueException {
        return new Date((Long)input);
    }

    @Override
    public Date parseLiteral(Object input) throws CoercingParseLiteralException {
        return new Date((Long)input);
    }
}
